package cn.com.taiji;

import com.jfinal.kit.PathKit;
import com.jfinal.kit.StrKit;

import cn.com.taiji.utils.InsertResource;
import cn.hutool.core.util.StrUtil;

/**
 * @author dongwei dongweia@mail.taiji.com.cn
 */

/**
 * taiji-frame 三层架构代码生成; 待优化数据准备;
 */
public class App {
    // 代码生成到目标工程的跟目录.如果不填,生成到当前工程.
    private static String targetProject = "E:\\eclipse-oxygen\\workspace\\TJ.sample-role";
    // 模块基本package
    private static final String basePackage = "cn.com.taiji.sample";
    // 自动生成代码的数据库表名
    private static final String[] tableNames = "SAMPLE_USERCARD".split(";");
    // 是否把新增controller分配给admin用户进行测试
    private static final boolean updateResource = false;

    static {
        // 测试生成到本工程,真实环境注释下面的targetProject = null;
        // targetProject = null;
        if (StrUtil.isBlank(targetProject)) {
            targetProject = PathKit.getWebRootPath();
            targetProject = targetProject.replaceAll("/war", "");
        }
    }

    public static void main(String[] args) {
        System.out.println("start!");
        RunCodegen.main(targetProject, basePackage, tableNames);
        System.out.println("---------刷新项目---------");
        System.out.println("管理系统中添加模块链接...");
        for (String tableName : tableNames) {
            System.out.println("app/acl/" + StrKit.toCamelCase(tableName) + "/manage");
        }
        if (updateResource) {
            for (String tableName : tableNames) {
                InsertResource.insertController(tableName);
            }
        }
    }

}
